<script setup lang='ts'>
import { RouterView, useRouter } from 'vue-router';
import { getAnchorApplayInfo, getGameGuildApplayInfo, getMCNApplayInfo } from '@/api/cooperation/index'
import { onMounted } from 'vue';
import { STDR } from '@/utils/http/types';
defineOptions({
  name: 'cooperation-index'
})
const router = useRouter()
onMounted(() => {
  Promise.allSettled([getAnchorApplayInfo(), getGameGuildApplayInfo(), getMCNApplayInfo()])
    .then((results) => {
      if (results.every(i => i.status === 'rejected')) {
        router.replace({ name: 'cooperation-register' })
        return
      }
      const rsult = (results).map<STDR<any> | null>((i) => {
        if (i.status === 'fulfilled') {
          return i.value
        } else {
          return null
        }
      })

      const [anchor, gameGuild, mcn] = rsult
      // console.log(anchor, gameGuild, mcn);
      if (anchor?.data) {
        const { verifyType } = anchor.data
        // 如果注册类型为解说,需要给予参数
        router.replace({ name: 'cooperation-anchor', params: { registryType: (verifyType && verifyType === 2) ? 'Commentary' : void 0 } })

      } else if (gameGuild?.data || mcn) {
        // 如果注册类型为工会,需要给予参数
        router.replace({ name: 'cooperation-org', params: { registryType: gameGuild?.data ? 'gameGuild' : void 0 } })
      }
    }, e => {
      console.error(e);
    })

})
function jump() {
  router.push({ name: 'cooperation-register' })
}
</script>

<template>
  <ElCard class="h-full" v-loading="true" element-loading-text="加载中...">

  </ElCard>

</template>

<style lang='scss' scoped></style>
